//
//  JJFeatureset.swift
//  swiftStudy
//
//  Created by hamilyjing on 2020/6/25.
//  Copyright © 2020 JJ. All rights reserved.
//

import Foundation

class JJFeatureset {
    weak var service: JJService?
    
    init() {
        
    }
    
    func startRequest(request request_: JJRequest) {
        startRequest(request: request_, successAction: nil, failAction: nil)
    }
    
    func startRequest(request request_: JJRequest, successAction successAction_: ((Any?, JJRequest) -> Void)?, failAction failAction_: ((Error?, JJRequest) -> Void)?) -> Void {
        request_.start(successCompletionBlock: { (baseRequest, model) in
            if (successAction_ != nil) {
                successAction_!(model, request_)
            }
            
            self.service?.response(isSuccess: true, model: model, error: nil, request: request_)
        }, failureCompletionBlock: { (baseRequest) in
            if (failAction_ != nil) {
                failAction_!(request_.responseError, request_)
            }
            
            self.service?.response(isSuccess: false, model: nil, error: request_.responseError, request: request_)
        })
    }
}
